##################################
##########   makefile     ########
##########   auto make *.c########
##################################
#PLAT_FORM=ARM
ifeq "$(PLAT_FORM)" "ARM"
CROSS_COMPILE = arm-hismall-linux-
else
CROSS_COMPILE =
endif

CC=$(CROSS_COMPILE)gcc
CC_PLUS=$(CORSS_COMPILE)g++
LD=$(CROSS_COMPILE)ld
AR=$(CROSS_COMPILE)ar
RAN=$(CROSS_COMPILE)ranlib
STRIP=$(CROSS_COMPILE)strip
MAKE=make
NULL=/dev/null

export CROSS_COMPILE CC AR LD CC_PLUS

LIBNAME = $(shell pwd |sed 's/^\(.*\)[/]//')
SRC = $(wildcard *.c)
SRC += $(wildcard *.cpp)
OBJECTS = $(patsubst %.cpp, %.o, $(patsubst %.c, %.o, $(SRC)))
SLIB = $(LIBNAME).a
#depend =$(patsubst %.cpp, %.o, $(patsubst %.c, %.d, $(SRC)))

INCLUDE = -I$(LIBNAME)/include

APPNAME = fork

CFLAGS = -Wall
CFLAGS += -g
CFLAGS += -o0
LDFLAGS = -lpthread

app: $(APPNAME)	
$(APPNAME) : $(OBJECTS)
	$(CC) -fPIC $(CFLAGS)  $(OBJECTS) $(LDFLAGS) -o $@
	
all: $(SLIB)
$(SLIB) : $(OBJECTS)
	@echo "----make $(SLIB) to $(APPNAME)-----"
	@$(AR) -rc -o $@ $(OBJECTS)

%.o: %.c
	$(CC) -c -fPIC $(CFLAGS) $< $(INCLUDE) $(LDFLAGS) -o $@
#	$(CC) -fPIC $(CFLAGS) -o $@ $<
	
.PHONY : clean

clean:
	-rm -rf $(SLIB) $(OBJECTS) $(APPNAME)
	